package com.example.controller;

import com.example.Paymodule.PayService;
import com.example.vo.PayVom;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pay")
public class PayController {
    private static final Logger logger = LoggerFactory.getLogger(PayController.class);

    @Autowired
    private PayService payService;


    @GetMapping("/alipay")
    public byte[] alipay(PayVom payVom) throws Exception {
        byte[] alipay=payService.alipay(payVom);
        return alipay;
    }




    @PostMapping("/alipay/callback")
    public String notify_yrl(HttpServletRequest request) throws Exception{
        Boolean result = payService.alipayCallback(request);
        if(result){
            System.out.println("callback success");
            return "success";
        }
        else {
            System.out.println("callback fail");
            return "fail";
        }

    }

}


